#! /bin/bash
# substring-extraction.sh
#


PATH="/usr/local/nagios/"
SNMPGET="/usr/bin/snmpget"
EXPR="/usr/bin/expr"
PROGNAME=`/usr/bin/basename $0`

PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.4 $' | /bin/sed -e 's/[^0-9.]//g'`

. $PROGPATH/utils.sh

print_usage() {
    echo "Usage: $PROGNAME -H Host -o OID -n name -w Warn in Grad -c Critical in Grad"
    echo "Usage: $PROGNAME --help"
    echo "Usage: $PROGNAME --version"
}

print_help() {
    print_revision $PROGNAME $REVISION
    echo ""
    print_usage
    echo ""
    echo "Temperatur via SNMP auslesen"
    echo ""
    support
}

# Make sure the correct number of command line
# arguments have been supplied

if [ $# -lt 1 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi

# Grab the command line arguments

exitstatus=$STATE_WARNING #default
while test -n "$1"; do
    case "$1" in
        --version)
            print_revision $PROGNAME $VERSION
            exit $STATE_OK
            ;;
        -V)
            print_revision $PROGNAME $VERSION
            exit $STATE_OK
            ;;
        --warn)
            warn=$2
            shift
            ;;
        -w)
            warn=$2
            shift
            ;;
        --critical)
            critical=$2
            shift
            ;;
        -c)
            critical=$2
            shift
            ;;
        --name)
            name=$2
            shift
            ;;
        -n)
            name=$2
            shift
            ;;
        --temp_oid)
            temp_oid=$2
            shift
            ;;
        -o)
            temp_oid=$2
            shift
            ;;
        --host)
            host=$2
            shift
            ;;
        -H)
            host=$2
            shift
            ;;
        -x)
            exitstatus=$2
            shift
            ;;
        --exitstatus)
            exitstatus=$2
            shift
            ;;
        *)
            echo "Unknown argument: $1"
            print_usage
            exit $STATE_UNKNOWN
            ;;
    esac
    shift
done

comm=public
#temp_oid=.1.3.6.1.4.1.5040.1.2.18.1.3.1.1.1
#dl_oid=".1.3.6.1.4.1.17587.2.1.1.19.0"
#dl=" 3,51"
#rdl_oid=".1.3.6.1.4.1.17587.2.1.2.3.0"


#	#Laser Name
#	laser=`/usr/bin/snmpget -O avq  -v 1 -c $comm $host $laser_oid`
	temp_str=`/usr/bin/snmpget -O avq  -v 1 -c $comm $host $temp_oid`
#	#RDL
#	rdl=`/usr/bin/snmpget -O avq -v 1 -c $comm $host $rdl_oid`
 
#	echo Ausgabe1 $temp_oid, $temp_str ,$warn, $critical
	 


	warn_int=$(echo $warn *10 | /usr/bin/bc -l)
	critical_int=$(echo $critical *10 | /usr/bin/bc -l)
	temp_int=$(echo $temp_str|/bin/sed 's/,//g'|/bin/sed 's/"//g')
	temp_pnp=$(echo $temp_str|/bin/sed 's/ //g'|/bin/sed 's/"//g')
#	echo $temp_int
	temp_ausg=$(echo "scale=1; $temp_int /10" |/usr/bin/bc -l)
#	echo $temp_2
	temp_grad=${temp_str:1:4}

#|sed 's/"//g'|sed 's/ //g'
#temp_int=CInt(i)
#temp_int=$temp_str(sed 's/"//g')
#temp_2=0
#temp_2=${temp_str:6:1}
#temp_3=$temp_1.$temp_2



#echo Ausgabe3 $temp_str, $temp_int, $temp_1, $temp_2, $temp_3, $temp
# lt=lower than, le=lower or equal
#temp_int, warn_int und critical_int sind die 10fachen Werte
#temp_ausg = .
#temp_pnp = ,

		if [[ $temp_int -ge $critical_int ]]; then
			exitstatus=2
			echo "Critical - $name $temp_ausg Grad | Temperatur=$temp_ausg;$warn;$critical"
		elif [[ $temp_int -ge $warn_int ]]; then
			exitstatus=1
			echo "WARNING - $name $temp_ausg Grad | Temperatur=$temp_ausg;$warn;$critical"
		elif [[ $temp_int -lt $warn_int ]]; then
			echo "OK - $name $temp_ausg Grad | Temperatur=$temp_ausg;$warn;$critical"
			exitstatus=0
		else
			exitstatus=3
			echo "Unknown - I see dead people - Something is wrong"
		fi
#echo $dl,$exitstatus
exit $exitstatus
